package algorithm;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:周次煜
 * Date: 2024-03-22
 * Time：23:29
 */


public class BF {

    // 暴力求解答的 BF 算法
        public static int BFfunc(String s1,String s2) {
            if (s1==null || s2==null) {
                    return -1;
            }
            if (s1.length()==0 || s2.length()==0) {
                return -1;
            }
            int i=0,j=0;

            int count=0;

            while (i<s1.length() && j<s2.length()) {
                if (s1.charAt(i)==s2.charAt(j) ) {
                    i++;
                    j++;
                }else {
                    i=i-j+1;
                    j=0;
                }

                count++;
            }

            System.out.println(count);

            if (j==s2.length()) {
                return i-j;
            }


            return -1;
        }

    public static void main(String[] args) {
        System.out.println(BFfunc("ababcabcdacac", "abcd"));

    }
}
